import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 3010,
    open: true,
    proxy: {
      '/dev/': {
        target: 'https://shop.sdamdyy.cn/dev',
        // target: 'http://localhost:8001',
        changeOrigin: true,
        rewrite: (path: string) => path.replace(/^\/dev/, '')
      },
      '/pic/': {
        target: 'https://shop.sdamdyy.cn/pic',
        changeOrigin: true,
        rewrite: (path: string) => path.replace(/^\/pic/, '')
      },
      '/prod/': {
        target: 'https://show.cool-admin.com',
        changeOrigin: true,
        rewrite: (path: string) => path.replace(/^\/prod/, '/api')
      }
    }
  },
  build: {
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return 'vendor'
          }
        }
      }
    }
  }
}) 